<?php  
class ControllerModuleSearchCondition extends Controller {
	protected function index() {
		$this->language->load('module/search_condition');
		
    	$this->data['heading_title'] = $this->language->get('heading_title');
    	$this->data['heading_title_2'] = $this->language->get('heading_title_2');
    	
    	$this->data['button_search'] = $this->language->get('button_search');
    	$this->data['text_tip'] = $this->language->get('text_tip');
    	$this->data['text_added'] = $this->language->get('text_added');
    	$this->data['text_removed'] = $this->language->get('text_removed');
    	
    	$this->data['entry_keyword'] = $this->language->get('entry_keyword');
    	$this->data['entry_district'] = $this->language->get('entry_district');
    	$this->data['entry_description'] = $this->language->get('entry_description');
    	
    	if (isset($this->request->get['filter_name'])) {
    		$filter_name = $this->request->get['filter_name'];
    	} else {
    		$filter_name = '';
    	}
    	
    	$this->data['filter_name'] = $filter_name;
    	
		if (isset($this->request->get['filter_description'])) {
    		$filter_description = $this->request->get['filter_description'];
    	} else {
    		$filter_description = false;
    	}
    	
    	$this->data['filter_description'] = $filter_description;
    	
    	if (isset($this->request->get['filter_option_value_ids'])) {
   	 		$filter_option_value_ids = explode(",", str_replace(' ', '', $this->request->get['filter_option_value_ids']));
       	} else {
	    	$filter_option_value_ids = array();
    	}
    	
    	$this->data['filter_option_value_ids'] = $filter_option_value_ids;
    	
    	if (isset($this->request->get['filter_district_id'])) {
      		$this->data['filter_district_id'] = $this->request->get['filter_district_id']; 	
		} else {
      		$this->data['filter_district_id'] = '';
    	}
    	
    	// Load all search otpions here
    	$this->load->model('tool/image');
    	$this->load->model('restaurant/option');
    	$this->data['options'] = array();
    	
    	$data = array('group' => 'restaurant');
    	
    	$options = $this->model_restaurant_option->getOptions($data);
    	
    	foreach ($options as $option) {
    		if ($option['type'] == 'select' || $option['type'] == 'radio' || $option['type'] == 'checkbox' || $option['type'] == 'image') {
    			$option_value_data = array();
    	
    			$data = array(
    								'option_id' => $option['option_id']
    			);
    	
    			$otion_values = $this->model_restaurant_option->getOptionValues($data);
    	
    			foreach ($otion_values as $option_value) {
    				$option_value_data[] = array(
    												'option_value_id'         => $option_value['option_value_id'],
    												'name'                    => $option_value['name'],
    												'image'                   => $this->model_tool_image->resize($option_value['image'], $this->config->get('config_image_restaurant_option_width'), $this->config->get('config_image_restaurant_option_height')),
    											    'total_restaurant'		  => $option_value['total_restaurant'],
    											    'href'					  => $this->url->link('restaurant/option', 'option_value_id=' . $option_value['option_value_id'])
    				);
    			}
    				
    			$this->data['options'][] = array(
    											'option_id'			=> $option['option_id'],
    											'name'              => $option['name'],
    											'image'             => $this->model_tool_image->resize($option['image'], $this->config->get('config_image_restaurant_option_width'), $this->config->get('config_image_restaurant_option_height')),
    											'category'          => $option['category'],
    											'type'              => $option['type'],
    											'option_value'      => $option_value_data
    			);
    		} elseif ($option['type'] == 'text' || $option['type'] == 'textarea' || $option['type'] == 'file' || $option['type'] == 'date' || $option['type'] == 'datetime' || $option['type'] == 'time') {
    			$this->data['options'][] = array(
    											'option_id'         => $option['option_id'],
    											'name'              => $option['name'],
    											'category'          => $option['category'],
    											'type'              => $option['type'],
    											'option_value'      => $option['option_value']
    			);
    		}
    	}    	
		
		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/search_condition.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/module/search_condition.tpl';
		} else {
			$this->template = 'default/template/module/search_condition.tpl';
		}
		
		$this->render();
  	}
}
?>